package com.wildworld.main;


import com.wildworld.core.IMap;
import com.wildworld.core.properties.MapProperty;
import com.wildworld.core.worldobjects.WorldObject;
import com.wildworld.coreimpl.IntelijWorldObject;
import com.wildworld.coreimpl.WildWorldImpl;
import com.wildworld.coreimpl.WildWorldMapImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author gzhebrakov
 *         Date: 24.06.12
 *         Time: 22:24
 */
public class Main {
    public static void main(String [] args){


        ApplicationContext context = new ClassPathXmlApplicationContext("services.xml");


        MapProperty mapProperty = new MapProperty();
        mapProperty.setWidth(1280);
        mapProperty.setHeight(800);
        mapProperty.setHerbPercent(30);
        mapProperty.setWaterPercent(20);

        WildWorldImpl world = new WildWorldImpl();

        IntelijWorldObject intelijWorldObjectMan = new IntelijWorldObject();
        intelijWorldObjectMan.move(100d, 100d);

        IntelijWorldObject intelijWorldObjectWoMan = new IntelijWorldObject();
        intelijWorldObjectWoMan.setGender(false);
        intelijWorldObjectWoMan.move(400d, 400d);

        world.addWorldObject(intelijWorldObjectMan);
        world.addWorldObject(intelijWorldObjectWoMan);

        ApplicationRunner runner = (ApplicationRunner) context.getBean("applicationRunner");

        IMap worldMap = runner.getMapService().generateMapByProperty(mapProperty);
        world.setWorldMap(worldMap);

        runner.getWorldService().setWorld(world);

        SwingTestWindow testWindow = new SwingTestWindow();
        worldMap.addRedrawEventListener(testWindow);
        runner.start();


        testWindow.setVisible(true);
    }
}
